package com.dream.network.utils;

import android.os.Looper;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Description: TODO
 * author: Wang
 * date: 3/9/17 16:43
 * email:life_artist@163.com
 * Copyright©2017 by wang. All rights reserved.
 */
public class ThreadHelper {

    private static final ExecutorService backgroundTasksExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2, new PriorityThreadFactory());

    public static void runOnUiThread(Runnable action) {
        ThreadUtils.runOnUiThread(action);
    }

    public static final boolean threadInMain() {
        if (Thread.currentThread().getId() == Looper.getMainLooper().getThread().getId()) {
            return true;
        }
        return false;
    }

    public static Future<?> runOnBackgroundThread(Runnable action) {
        if (action == null) {
            return null;
        }
        return backgroundTasksExecutor.submit(action);
    }
}
